﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using System.IO;

namespace DuAnNH
{
    class Cls_XML
    {
        public void LuuXML(string sv, string csdl, string un, string pwd)
        {
            string file = "Config.xml";
            XmlTextWriter xml = new XmlTextWriter(file, null);
            xml.Formatting = Formatting.Indented;
            xml.WriteStartDocument();
            xml.WriteStartElement("Config");
            xml.WriteStartElement("sever");
            xml.WriteString(sv);
            xml.WriteEndElement();
            xml.WriteStartElement("database");
            xml.WriteString(csdl);
            xml.WriteEndElement();
            xml.WriteStartElement("user");
            xml.WriteString(un);
            xml.WriteEndElement();
            xml.WriteStartElement("pass");
            xml.WriteString(pwd);
            xml.WriteEndElement();
            xml.WriteEndElement();
            xml.WriteEndDocument();
            xml.Close();
        }
        public void LuuConXML()
        {
            string file = "Config.xml";
            XmlTextWriter xml = new XmlTextWriter(file, null);
            xml.Formatting = Formatting.Indented;
            xml.WriteStartDocument();
            xml.WriteStartElement("Config");
            xml.WriteStartElement("sever");
            xml.WriteString("REVNTy1QQ1xTUUwyMDA1YmluaG1pbmg=");
            xml.WriteEndElement();
            xml.WriteStartElement("database");
            xml.WriteString("bmhhaGFuZ2JpbmhtaW5o");
            xml.WriteEndElement();
            xml.WriteStartElement("user");
            xml.WriteString("c2FiaW5obWluaA==");
            xml.WriteEndElement();
            xml.WriteStartElement("pass");
            xml.WriteString("c2FiaW5obWluaA==");
            xml.WriteEndElement();
            xml.WriteEndElement();
            xml.WriteEndDocument();
            xml.Close();
        }

        public void LuuBan(int i,string matd, string tentd, string sl, string gia)
        {
            int j;
            string file = "ban.txt";
            XmlTextWriter xml = new XmlTextWriter(file, null);
            xml.Formatting = Formatting.Indented;
            xml.WriteStartDocument();
            xml.WriteStartElement("ban");
            for (j = 0; j < i; j++)
            {
                xml.WriteStartElement("MaThucDon");
                xml.WriteString(matd);
                xml.WriteEndElement();

                xml.WriteStartElement("TenThucDon");
                xml.WriteString(tentd);
                xml.WriteEndElement();

                xml.WriteStartElement("SoLuong");
                xml.WriteString(sl);
                xml.WriteEndElement();

                xml.WriteStartElement("DonGia");
                xml.WriteString(gia);
                xml.WriteEndElement();
            }
            xml.WriteEndElement();
            xml.WriteEndDocument();
            xml.Close();
        }
        public void GhiText(string matd, string tentd, string sl, string gia)
        {
            System.IO.StreamWriter str = System.IO.File.AppendText("Text.txt");
            str.WriteLine(matd + "," + tentd + "," + sl + "," + gia);
            //str.WriteLine(tentd);
            //str.WriteLine(sl);
            //str.WriteLine(gia);
            str.Close(); 
            
        }
        public void DocXML()
        {
            string file = "Config.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(file);
            XmlElement element = doc.DocumentElement;
            string sv = element.SelectSingleNode("sever").InnerText;
            string csdl = element.SelectSingleNode("database").InnerText;
            string un = element.SelectSingleNode("user").InnerText;
            string pwd = element.SelectSingleNode("pass").InnerText;
            MessageBox.Show(sv + "\n" + csdl + "\n" + un + "\n" + pwd);
        }
    }
}
